#include <stdlib.h>

#include "lib.h"

#include "slotguts.h"
#include "llguts.h"



enum LL_WheelContents 
{ 
    BLANK, 
    BAR1, 
    SEVEN, 
    ORANGE, 
    CHERRY, 
    PLUM, 
    BAR2
};


enum SpinResult
{
	EVT_LOSER = 0,
	EVT_3BLANK,
	EVT_1CHERRY,
	EVT_ANY3BARS,
	EVT_3BARS,
	EVT_2CHERRIES,
	EVT_3PLUMS,
	EVT_3CHERRIES,
	EVT_3ORANGES,
	EVT_3BARBARS,
	EVT_3SEVENS,
	NUMEVENTS,
};

bool8 
LLSlotGuts::isValidGuts()
{
    return getGutsId() == 0 ||
           getGutsId() == 1 ||
           getGutsId() == 2 ||
           getGutsId() == 3 ||
           getGutsId() == 4 ||
           getGutsId() == 5 ||
           getGutsId() == 6 ||
           getGutsId() == 7;
}


uint8
LLSlotGuts::classifyStops(uint8* stops,uint8 bet, uint8 line)
{
	uint8 result = EVT_LOSER;


	// 3-in-a-row
	//

	if ( getIcon(0, stops[0])->iconid == getIcon(1, stops[1])->iconid &&
		getIcon(1, stops[1])->iconid == getIcon(2, stops[2])->iconid)
	{
		switch ( getIcon(0, stops[0])->iconid )
		{
			case BLANK:
                result = EVT_3BLANK;
                break;
			case CHERRY:	
                result = EVT_3CHERRIES;	
                break;
			case PLUM:		
                result = EVT_3PLUMS;
                break;
			case ORANGE:
                result = EVT_3ORANGES;
                break;
			case BAR1:
                result = EVT_3BARS;
                break;
			case BAR2:
                result = EVT_3BARBARS;
                break;
			case SEVEN:
                result = EVT_3SEVENS;
                break;
			default:
				break;
		}
	}
	else
	{
		int32 i, bars = 0, cherries = 0;

		for (i = 0; i < getReelCount(); i++)
        {
            uint8 icon = getIcon(i, stops[i])->iconid;
			switch ( icon )
			{
				case CHERRY:
					++cherries;
					break;
				case BAR1:
				case BAR2:
					++bars;
					break;
				default:
					break;
			}
        }

		if (bars == 3)
			result = EVT_ANY3BARS;
		else if (cherries > 0)
			result = (cherries == 2 ? EVT_2CHERRIES : EVT_1CHERRY);
	}



	return result;
}

#ifdef DEBUGSPIN
void LLSlotGuts::Debug_SetLoserStops( uint8* pStops )
{
	pStops[0] = 2;
	pStops[1] = 2;
	pStops[2] = 11;
}
#endif